package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.beautyescort.BeautyEscortModule;
import com.yanqu.road.server.manger.beautyescort.BeautyEscortMgr;
import com.yanqu.road.server.manger.config.UnionConfigMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

/**
 * 美女走镖加速
 */
public class UseReduceBeautyEscortTime extends BaseUseGoods {

    public UseReduceBeautyEscortTime(GamePlayer player, GoodsInfo goodsInfo, long param) {
        super(player, goodsInfo, param);
    }

    @Override
    int checkUse(long count) {
        if(StringUtils.isNullOrEmpty(player.getUserInfo().getUnionUid())){
            return GameErrorCode.E_UNION_NO_JOIN_UNION;
        }
        //商会等级限制
        UnionInfo unionInfo = CrossUnionMgr.getUnionInfo(player.getUserInfo().getUnionUid());
        if(UnionConfigMgr.getUnionLv(unionInfo.getExperience()) < GameConfig.ESCORT_OPEN_UNION_LEVEL) {
            return GameErrorCode.E_BEAUTY_ESCORT_UNION_LEVEL_NO_ENOUGH;
        }
        return 0;
    }

    @Override
    UseGoodsResult executeUse(long count) {
        UseGoodsResult result = new UseGoodsResult();
        BigInteger min = goodsInfo.getParamList().get(0);
        int num = (int)count;
        player.getModule(BeautyEscortModule.class).reduceEscortTime(min.intValue(), num, (int)param);
        return result;
    }
}
